<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <title>密码修改</title>
    <%@include file="/WEB-INF/pages/common/taglib.jsp" %>
    <%@include file="/WEB-INF/pages/common/common.jsp" %>
</head>
<body>
<div>
    <div class="header_line">
        当前位置：用户信息管理<span>&gt;</span><strong>密码修改</strong>
    </div>
    <div class="mt10"></div>
    <form id="form_data" action="${basePath}/center/updatePassword">
        <table class="table_detail">
            <tr class="tr_header">
                <td colspan="2">&nbsp;&nbsp;密码修改</td>
            </tr>
            <tr>
                <td class="width30p"><label><em>*</em>原密码</label></td>
                <td class="width70p"><input type="password" name="password_old" placeholder="请输入原密码"/></td>
            </tr>
            <tr>
                <td class="width30p"><label><em>*</em>新密码</label></td>
                <td class="width70p"><input id="password_new" type="password" name="password_new" placeholder="请输入新密码"/>
                </td>
            </tr>
            <tr>
                <td class="width30p"><label><em>*</em>确认新密码</label></td>
                <td class="width70p"><input type="password" name="password_again" placeholder="请输入确认新密码"/></td>
            </tr>
            <tr class="tr_button">
                <td colspan="2">
                    <input type="submit" value="提交">
                </td>
            </tr>
        </table>
    </form>
</div>
<script>
    jQuery.validator.addMethod("checkPassword", function (value) {
        var result = false;
        $.ajax({
            url: "${basePath}/center/checkOldPassword",
            data: {password: value},
            async: false,
            success: function (data) {
                if (data) {
                    result = true;
                }
            }
        });
        return result;
    }, '原密码不正确！');
    $(function () {
        if (${status eq 1}) {
            layer.alert("密码修改成功！", {icon: 6});
            $("input[type='password]").val("");
        }
        if (${status eq 0}) {
            layer.alert("密码修改失败！", {icon: 5})
        }
        $("#form_data").validate({
            debug: false, //false表示验证通过后不要自动提交表单
            onkeyup: false, //表示关闭按键松开时候监听验证
            rules: {
                password_old: {
                    required: true
                },
                password_new: "required",
                password_again: {
                    equalTo: "#password_new"
                }
            },
            messages: { //自定义错误信息，默认为英文，除了在这里配置以为，还可以通过配置文件进行配置
                password_old: {
                    required: "请输入原密码！"
                },
                password_new: {
                    required: "请输入新密码！"
                },
                password_again: {
                    equalTo: "新密码输入不一致！"
                }
            },
            //验证通过可以在这里做你想做的事情
            submitHandler: function (form) {
                form.submit();
            }
        });
    });
</script>
</body>
</html>